<template>
  <!--通讯录 添加联系人 -->
  <section class="component add-contact">
    <el-form
      ref="form"
      :rules="rules"
      label-width="120px"
      :model="model"
      inline
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="角色：" prop="custType">
            <el-select placeholder="请选择" v-model="model.custType">
              <el-option
                v-for="{ index, name, code } in $dict.getDictData('CustType')"
                :key="index"
                :label="name"
                :value="code"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="姓名：" prop="contName">
            <el-input v-model="model.contName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="性别：" prop="sex">
            <el-select placeholder="请选择" v-model="model.sex">
              <el-option
                v-for="{ index, name, code } in $dict.getDictData('Sex')"
                :key="index"
                :label="name"
                :value="code"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="关系：" prop="relation">
            <el-select placeholder="请选择" v-model="model.relation">
              <el-option
                v-for="{ index, name, code } in $dict.getDictData(
                  'Relationship'
                )"
                :key="index"
                :label="name"
                :value="code"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="身份证号：" prop="idNumber">
            <el-input v-model="model.idNumber"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="电话号码：" prop="phone">
            <el-input v-model="model.phone"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="身份证地址：" prop="idCardAddress">
        <el-input v-model="model.idCardAddress" style="width:95%"></el-input>
      </el-form-item>
      <el-form-item label="现居住地：" prop="contAddress">
        <el-input v-model="model.contAddress" style="width:95%"></el-input>
      </el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="现居住电话：" prop="homePhone">
            <el-input v-model="model.homePhone"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工作单位：" prop="companyName">
            <el-input v-model="model.companyName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="单位电话：" prop="companyPhone">
        <el-input v-model="model.companyPhone"></el-input>
      </el-form-item>
      <el-form-item label="工作地址：" prop="companyAddress">
        <el-input v-model="model.companyAddress" style="width:95%"></el-input>
      </el-form-item>
    </el-form>
    <div class="confirm-button">
      <el-button @click="emitClose">取消</el-button>
      <el-button @click="submit">确定</el-button>
    </div>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Form } from "element-ui";
import { Dependencies } from "~/core/decorator";
import { Emit } from "vue-property-decorator";
import { CaseOperatorPageService } from "~/services/domain-service/case-operator-page.service";
import { namespace } from "vuex-class";
const CollectionExecutionModule = namespace("collection-execution");
import { MENU_CHANNEL } from "~/config/enum.config";

@Component({
  components: {}
})
export default class AddContact extends Vue {
  @Dependencies(CaseOperatorPageService)
  @Dependencies(CaseOperatorPageService)
  private caseOperatorPageService: CaseOperatorPageService;
  @CollectionExecutionModule.State private caseId;
  @CollectionExecutionModule.State private menuChannel;
  @CollectionExecutionModule.State private otherData;
  private disabledDataSource = ["IMPORT", "INTERFACE"];
  private model: any = {};
  private rules: any = {};

  @Emit("close")
  private emitClose() {
    const form: any = this.$refs["form"];
    form.resetFields();
  }

  private created() {
    this.model = {
      caseId: "",
      custType: "",
      contName: "",
      sex: "",
      relation: "",
      idNumber: "",
      phone: "",
      idCardAddress: "",
      contAddress: "",
      homePhone: "",
      companyName: "",
      companyPhone: "",
      companyAddress: ""
    };
    this.rules = {
      custType: { required: true, message: "请选择角色" },
      contName: { required: true, message: "请输入联系人姓名" },
      sex: { required: true, message: "请选择性别" },
      // idNumber: { required: true, message: "请输入身份证号" },
      phone: { required: true, message: "请输入联系人号码" },
      relation: { required: true, message: "请选择客户关系" }
    };
  }

  private submit() {
    const form = this.$refs.form as Form;
    form.validate(v => {
      if (!v) return;
      if (
        this.menuChannel === MENU_CHANNEL.Assist_tel ||
        this.menuChannel === MENU_CHANNEL.Assist_visit ||
        this.menuChannel === MENU_CHANNEL.Assist_legal
      ) {
        this.model.assistId = this.otherData.assistId;
      }
      this.model.caseId = this.caseId;
      this.caseOperatorPageService
        .addPersonalContact(this.model)
        .subscribe(data => {
          this.$message.success("操作成功");
          form.resetFields();
          this.emitClose();
        });
    });
  }
}
</script>

<style scoped lang="less"></style>
